<template name="redContent">
<view class="red">
    <view class="footer_red">
        <view class="red_money" @click="redOpen">
            {{redtext}}
        </view>
    </view>
    <view class="next" v-if="nexttrue" @click="toLogin">
            下一步
    </view>
</view>
</template>
<script>
import request from '@/util/request.js'
export default {
	name: "redContent",
	data() {
		return {
			redtext:'開',
			nexttrue:false
		}
	},
	//属性
	props: {


	},
	//组件生命周期
	methods:{
		redOpen:function(){
			if(this.redtext !== '開'){
				//console.log('开过')
				return;
			}
			var money = Math.floor(Math.random()*2);
			if(money == 0){
			      money = 1;
			}
			this.redtext = money+'.00'
			this.addMoney(money);
		},
		addMoney:function(money){
			//uni.setStorageSync('uid',12)
			var that = this;
			var data = {
				'uid':uni.getStorageSync('uid'),
				'money':money,
			}
			request({
			 	url: 'money/add',
			 	method: 'post',
			 	data:data,
			 	success: (res) => {
					//console.log(res)
					if(res.data.code == 1){
						uni.showToast({
						    title:'领取红包成功可在个人中心,我的红包查看!!!!',
						    icon: "none", 
						    position:'bottom',
						})
						that.nexttrue = true
					}else{
						uni.showToast({
						    title:res.data.msg,
						    icon: "none", 
						    position:'bottom',
						})
					}
				},
			})
		},
		toLogin:function(){
			if(uni.getStorageSync('role') !== 1){
				uni.switchTab({
					url:'/pages/index/index'
				})
			}else{
				uni.navigateTo({
					url:'/pages/login/index'
				});
			}
		}
		// ruleBack:function(){
		// 	this.$emit('func',false)
		// }
	}
}
</script>
<style>
.red{
    position: fixed;
    top: 0;
    left: 0%;
    width: 100%;
    height: 100%;
    padding-top: 30%;
    padding-left: 5%;
    padding-right: 5%;
    background-color: black;
    z-index: 99;
    background: rgba(0,0,0,0.7);
}

.footer_red{
    display: flex;
    margin-left: 5%;
    width: 80%;
    height: 580rpx;
    background:rgb(214,52,50);
    border-radius: 20px;
    justify-content: center;
    align-items: center;
  }
  .red_money{
    justify-content: center;
    align-items: center;
    display: flex;
    width:240rpx;
    height:240rpx;
    background:rgb(255,198,92);
    font-size:35px;
    border-radius: 120rpx;
    color:rgb(255,122,0)
  }
.next{
    width:70%;height:40px;line-height:40px;
    text-align:center;background: #44b549;
    margin-top:10rpx;
    margin-left:10%;border-radius: 20px;}
</style>